//
//  TrainingActionRow.swift
//  Fitness
//
//  Created by duanwenpu on 2021/9/10.
//

import SwiftUI

typealias ConfirmBlock = (_ actionTime: String, _ perWeight: String, _ restTime: String, _ index: Int) -> ()

struct TrainingActionRow: View {
    @State var trainingModel: TrainingModel
    @State var edit: Bool = false
    var confirmBlock: ConfirmBlock
    @State private var showActionTimes: String = ""
    
    @State private var showPerWeight: String = ""
    @State private var showRestTime: String = ""
    var body: some View {
        HStack(alignment: .center, spacing: 20, content: {
            TextField(
                "\(trainingModel.actionTimes)次",
                text: $showActionTimes
            )
            .background(Color.red)
            .keyboardType(.numberPad)
            .disabled(!edit)
            TextField(
                "\(trainingModel.perWeight)kg",
                text: $showPerWeight
            )
            .keyboardType(.numberPad)
            .disabled(!edit)
            TextField(
                "\(trainingModel.restTime)秒",
                text: $showRestTime
            )
            .keyboardType(.numberPad)
            .disabled(!edit)
            if edit {
                Button(action: {
                    self.confirmBlock(self.showActionTimes, self.showPerWeight, self.showRestTime, trainingModel.id)
                }, label: {
                    Text("确定")
                })
            }
        })
    }
}
